<?php
declare (strict_types = 1);

namespace app\api\controller;

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;

class Index
{
    public function index()
    {
//        $re = file_get_contents(public_path().'re.txt');
//        var_dump(json_decode($re));exit;
//        $path = '/search/tree?excludeIllustrations=true&searchPathTree=%252F0000-Articulated%2520Loaders';
//        $date = date('Ymd');
//        $AccessKeyId = 'ASIAXRK4ZK2H5WQUZYUF';
//        $secretAccessKey = 'PD2NvW2TeNXcpxOf/4BLa0/pi/C3PfuDYWYQCIFD';
//        $Signature = '';
//        $kDate = hash_hmac('sha256', $date, 'AWS4'.$secretAccessKey);
//        $kRegion = hash_hmac('sha256', 'us-east-1', $kDate);
//        $kService  = hash_hmac('sha256', 's3', $kRegion);
//        $kSigning  = hash_hmac('sha256', 'aws4_request', $kService);
//
//        $credentialString = implode('/',[$date,'us-east-1','s3','aws4_request']);
//        $headers = [
//            'authorization' => "AWS4-HMAC-SHA256 Credential=$AccessKeyId/".$date."/us-east-1/execute-api/aws4_request, SignedHeaders=accept;host;x-amz-date, Signature=dcdeacbae2be5d5833526fbbbac208163bdd2af6f94cfb817c575cdfddab3510",
//            'x-amz-date' => '20220107T092020Z',
//            'x-amz-security-token' => 'FwoGZXIvYXdzENf//////////wEaDMFoAE2o1JKNXAWdMCKkAspJZ6e+d3w4bi07e8uYG0t8WeGE9/zdYufR0AYnm6Qccg0MRN15uHm7Q72g7FPDjD59ZAnERUwSgJx0dxd4GUjsukImVivGJO85VCbSdgPmpMHmboiHQhPzpy6OP1m37UPXNe8rjtjq3uCc5Yb5CC5pOEdH65Kbeakl3Tm/+ztIYdHelsqiB/YjdbKxaAtvoku+0cMoqUSCBd9jkhX4XDMPVhJf77kC9Hpd04Yoa8mLcgFNFdU3/3WwtMjdAISYvKpFnWqhwgl01WH6ElcKCCqq3GSA+Gwv4vNKwE1ZSGJxBtm8pkOq3okFJJJ+I4ngEDIXcpjmC22xF94116oUaFduy7qRTRevQbiPQyfM1rJdHABAx9Sm5e9lhY9d3lxTB3lFY18o5MfkjgYylgF0TB0AEN12Hh77DEPdoqU6LG9I6hQj3iaw48dyCoquotBpBlaPO0H2NW2pVyn3A9lkcj19xXpWIf58QbX+FZeicSNxqzjENMcZzaZfqke+04rOg4hZf3/MAoBasBhoezjOgZqZbk7+RRlnQ4p/+FEiKgy8bxQ9E3CD3RA8O5I23hMttrogl0lZdadnsg+vv/XSCcb2+TI='
//        ];
//        $headers[':authority'] = 'opc.api.bobcat.com';
//        $headers[':method'] = 'GET';
//        $headers[':path'] = $path;
//        $headers[':scheme'] = 'https';
//        $headers['accept'] = 'application/json';
//        $headers['accept-encoding'] = 'gzip, deflate, br';
//        $headers['accept-language'] = 'zh-CN,zh;q=0.9';
//        /*
//         cache-control: no-cache
//content-type: application/json
//origin: https://www.bobcatpartsonline.com
//pragma: no-cache
//referer: https://www.bobcatpartsonline.com/
//sec-ch-ua: "Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"
//sec-ch-ua-mobile: ?0
//sec-fetch-dest: empty
//sec-fetch-mode: cors
//sec-fetch-site: cross-site
//user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36
//         * */
//        $headers['cache-control'] = 'no-cache';
//        $headers['content-type'] = 'application/json';
//        $headers['origin'] = 'https://www.bobcatpartsonline.com';
//        $headers['pragma'] = 'no-cache';
//        $headers['referer'] = 'https://www.bobcatpartsonline.com/';
//        $headers['sec-ch-ua'] = '"Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"';
//        $headers['sec-ch-ua-mobile'] = '?0';
//        $headers['sec-fetch-dest'] = 'empty';
//        $headers['sec-fetch-mode'] = 'cors';
//        $headers['sec-fetch-site'] = 'cross-site';
//        $headers['user-agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36';
//       //$headers[''] = '';
//
//        ksort($headers);
//        $SignableHeader = [];
//        $signedHeaders = [];
//        foreach($headers as $key=>$header){
//            if(substr(strtolower($key),0,6) == 'x-amz-' || !in_array($key,["authorization", "content-type", "content-length", "user-agent", "presigned-expires"])){
//                $SignableHeader[] = strtolower($key).':'.preg_replace('/^\s+|\s+$/g', "",preg_replace('/\s+/g', " ",$header));
//                $signedHeaders[] = strtolower($key);
//            }
//
//        }
//
//        $canonicalString = implode("\n",[
//            'GET',
//            $date,
//            substr($path,strpos($path,'?')),
//            implode("\n",$SignableHeader)+"\n",
//            implode(";",$signedHeaders),
//            'us-east-1',
//            's3',
//            'aws4_request'
//        ]);
//        var_dump($date);exit;
//        $body = 'Hello!';
//        $request = new Request('HEAD', 'https://opc.api.bobcat.com/search/tree?excludeIllustrations=false&searchPathTree=%252F0000-Articulated%2520Loaders%252F0000-WL440', $headers, $body);
//
//        $client = new Client([
//            // Base URI is used with relative requests
//            'base_uri' => 'https://opc.api.bobcat.com'.$path,
//            // You can set any number of default request options.
//            'timeout'  => 2.0,
//        ]);
//
//        $reponse = $client->request('get','https://opc.api.bobcat.com'.$path,[
//            'headers' => $headers
//        ]);

//        var_dump(json_decode($reponse->getBody()->getContents()));exit;
        return '您好！这是一个[api]示例应用';
    }

    public function list(){
        file_put_contents('reponse.txt',var_export(\request()->param(),true));
    }
}
